﻿#include "EditorAddComponentPropertyViewModel.h"

#include "Window/EditorWindowGroupViewModel.h"

#include "Scene/StaticMeshComponent.h"
#include "Scene/DirectionalLightComponent.h"
#include "Scene/PointLightComponent.h"
#include "Scene/SpotLightComponent.h"
#include "Scene/CameraComponent.h"
#include "Scene/SceneNode.h"
#include "Scene/SkyBoxComponent.h"
#include "Scene/AmbientLightComponent.h"

#include "Scene/SceneNodeComponent.h"

#include "Ability/ObjectProperty/EditorObjectPropertyAbilityViewModel.h"

void REditorAddComponentPropertyViewModel::BindModel(TSharedObjectPtr<REditorPropertyModel> InModel, TSharedObjectPtr<REditorObjectPropertyAbilityViewModel> InAbilityViewModel)
{    
    Super::BindModel(InModel,InAbilityViewModel);
    AddComponentModel = InModel;
}

void REditorAddComponentPropertyViewModel::OnAddComponentClicked(TSharedObjectPtr<RWidget> InButtonWidget)
{
    
    //make a context menu to select the component to add
    TVector<SEditorContextMenuLine> RootContextMenu;

    //add render group
    {
        auto& Render= RootContextMenu.Emplace();
        Render.Text=U"网格";
        Render.SubMenuWidth=150;
                
        //second level 
        {
            auto& StaticMesh=Render.SubMenus.Emplace();
            StaticMesh.Text=U"静态网格";
            StaticMesh.OnClicked.Bind([this](){
                AddComponent(RStaticMeshComponent::StaticClass());
            });
        }

        {
            auto& SkyBox=Render.SubMenus.Emplace();
            SkyBox.Text=U"天空盒";
            SkyBox.OnClicked.Bind([this](){
                AddComponent(RSkyBoxComponent::StaticClass());
            });
        }
    
    }

    //add camera group
    {
        auto& Camera= RootContextMenu.Emplace();
        Camera.Text=U"摄像机";
        Camera.SubMenuWidth=150;
                
        //second level 
        {
            auto& CameraComponent=Camera.SubMenus.Emplace();
            CameraComponent.Text=U"摄像机";
            CameraComponent.OnClicked.Bind([this](){
                AddComponent(RCameraComponent::StaticClass());
            });
        }
    
    }   

    //add Light group
    {
        auto& Light= RootContextMenu.Emplace();
        Light.Text=U"光照";
        Light.SubMenuWidth=150;
                
        //second level 
        {
            auto& DirectionalLight=Light.SubMenus.Emplace();
            DirectionalLight.Text=U"平行光";
            DirectionalLight.OnClicked.Bind([this](){
                AddComponent(RDirectionalLightComponent::StaticClass());
            });
        }

        {
            auto& PointLight=Light.SubMenus.Emplace();
            PointLight.Text=U"点光源";
            PointLight.OnClicked.Bind([this](){
                AddComponent(RPointLightComponent::StaticClass());
            });
        }

        {
            auto& SpotLight=Light.SubMenus.Emplace();
            SpotLight.Text=U"聚光灯";
            SpotLight.OnClicked.Bind([this](){
                AddComponent(RSpotLightComponent::StaticClass());
            });
        }
    
        {
            auto& AmbientLight=Light.SubMenus.Emplace();
            AmbientLight.Text=U"环境光";
            AmbientLight.OnClicked.Bind([this](){
                AddComponent(RAmbientLightComponent::StaticClass());
            });

        }
    }   
                

    REditorWindowGroupViewModel::Get()->ShowContextMenu(
        RootContextMenu
        ,InButtonWidget
    );
}

void REditorAddComponentPropertyViewModel::AddComponent(TSubclassOf<RSceneNodeComponent> InComponentClass)
{
    AbilityViewModel->AddComponent(InComponentClass);
}
